<!DOCTYPE html>
<html lang="zh-cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" th:href="@{/css/pintuer.css}">
    <link rel="stylesheet" th:href="@{/css/admin.css}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <style>
        .cz a{
            border-radius:3px; border:1px solid #dfdfdf;display:inline-block; padding:5px 12px;
        }
        .cz a:hover{background:#09F; color:#FFF; border-color:#09F; }
    </style>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 分栏列表</strong></div>
    <div class="padding border-bottom">
        <div class="layui-form-item layui-inline">
            <label class="layui-btn layui-form-label" style="text-align: center" th:onclick="query()">查询</label>
            <div class="layui-input-block">
                <input class="layui-input" id="title" name="title" placeholder="输入文件名" th:value="${title}" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item layui-inline">
            <label class="layui-btn " style="text-align: center" th:onclick="add()" ><i class="layui-icon">&#xe654;</i></label>
        </div>
        <form id="form1"  class="layui-form layui-inline">
            <div class="layui-form-item layui-form-text layui-inline">
                <div class="layui-input-block">
                    <input id="cut" name="cut" type="checkbox" lay-skin="switch" th:value="${cut}" lay-filter="cut" lay-text="文章分栏|资源分栏" th:checked="${cut+'' == '1'}">
                </div>
            </div>
        </form>
    </div>

    <table class="table table-hover text-center" th:if="${cut} == 1">
        <tr>
            <th width="20%">分栏名称</th>
            <th width="20%">文章数量</th>
            <th width="20%">创建时间</th>
            <th width="20%">前台显示</th>
            <th width="20%">操作</th>
        </tr>
        <tbody>
        <tr th:each="group:${groups}">
            <th th:text="${group.getGroupsId()}" style="display: none"></th>
            <td class="breakword" title="双击可修改" th:text="${group.getGname()}"></td>
            <td ><span th:text="${group.getGnum()}"></span></td>
            <td th:text="${#dates.format(group.getCreateTime(),'yyyy-MM-dd HH:mm:ss')}">1</td>
            <td>
                <form id="form2"  class="layui-form">
                    <input id="1" name="top1" type="checkbox" lay-skin="switch" th:value="${group.getGroupsId()}+'-'+${group.getGshow()}"  lay-filter="switchTest" lay-text="NO|OFF" th:checked="${group.getGshow()+''=='1'}">
                </form>
            </td>
            <td  class="cz">
                <a th:href="@{/group/delGroup/}+${group.getGroupsId()}"><i class="layui-icon">&#xe640;</i></a>
            </td>
        </tr>
        </tbody>
    </table>
    <table class="table table-hover text-center" th:if="${cut} == 0">
        <tr>
            <th width="20%">分栏名称</th>
            <th width="20%">资源数量</th>
            <th width="20%">创建时间</th>
            <th width="20%">前台显示</th>
            <th width="20%">操作</th>
        </tr>
        <tbody>
            <tr th:each="filegroup:${filegroups}">
                <th th:text="${filegroup.getFilegroupId()}" style="display: none"></th>
                <td class="breakword" title="双击可修改" th:text="${filegroup.getFgname()}"></td>
                <td th:text="${filegroup.getGnum()}"></td>
                <td th:text="${#dates.format(filegroup.getCreateTime(),'yyyy-MM-dd HH:mm:ss')}"></td>
                <td>
                    <form id="form3"  class="layui-form">
                        <input name="top1" type="checkbox" lay-skin="switch" th:value="${filegroup.getFilegroupId()}+'-'+${filegroup.getGshow()}"  lay-filter="fileGroup" lay-text="NO|OFF" th:checked="${filegroup.getGshow()+''=='1'}">
                    </form>
                </td>
                <td class="cz">
                    <a th:href="@{/group/delFileGroup/}+${filegroup.getFilegroupId()}"><i class="layui-icon">&#xe640;</i></a>
                </td>
            </tr>
        </tbody>
    </table>
</div>

</body>
<script th:src="@{/js/jquery-2.1.0.js}"></script>
<script th:src="@{/js/pintuer.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script th:inline="javascript">
    layui.use('form', function(){
        var form = layui.form;
        //资源管理部分 cut = 0 走非默认
        form.on('switch(cut)', function(data){

            var cut=this.value;
            if (cut == 1){
                window.location.href="/group/data_group?cut=0";
            }else {
                window.location.href="/group/data_group?cut=1";
            }

        });
        //文章部分 不传cut 走默认
        form.on('switch(switchTest)', function(data){

            var str=this.value;
            var arr=new Array();
            arr=str.split('-');
            var flage=false;
            $.ajax({
                type:'post',
                url:"/group/updateGroup/"+arr[0]+"/"+"0"+"/"+arr[1],
                dataType: "text",
                async: false,
                success:function (res) {
                    if (res==1){
                        flage=false;
                    }else {
                       flage=true;
                    }
                }
            });
            if (flage){
                layer.tips('温馨提示：不要频繁修改', data.othis)
            }else {
                layer.msg('文章组已：'+ (this.checked ? '显示' : '取消显示'), {
                    offset: '6px'
                });
            }

        });
        form.on('switch(fileGroup)', function(data){

            var str=this.value;
            var arr=new Array();
            arr=str.split('-');
            var flage=false;
            $.ajax({
                type:'post',
                url:"/group/updateFileGroup/"+arr[0]+"/"+"0"+"/"+arr[1],
                dataType: "text",
                async: false,
                success:function (res) {
                    if (res==1){
                        flage=false;
                    }else {
                        flage=true;
                    }
                }
            });
            if (flage){
                layer.tips('温馨提示：不要频繁修改', data.othis)
            }else {
                layer.msg('资源组已：'+ (this.checked ? '显示' : '取消显示'), {
                    offset: '6px'
                });
            }
        });
    });
    function query(){
        var title=$("#title").val();

        var cut =$("#cut").val();
        window.location.href="/group/data_group?title="+title+'&cut='+cut;
    }
    function add(){
        var title=$("#title").val();

        var cut =$("#cut").val();
        if (cut==1){
            window.location.href="/group/addGroup/"+title;
        }else {
            window.location.href="/group/addFileGroup/"+title;
        }

    }
    $(function() {
        $('td.breakword').dblclick(function(){
            $(this).addClass('input').html('<input type="text" value="'+ $(this).text().replace(/[\r\n\s]/g,"") +'" />').find('input').focus().blur(function(){
                var thisid = $(this).parent().siblings("th").text().replace(/[\r\n\s]/g,"");
                var thisvalue=$(this).val().replace(/[\r\n\s]/g,"");
                var cut =$("#cut").val();

                if (cut==1){
                    //文章组
                    $.ajax({
                        type: 'POST',
                        url: '/group/updateGroup/'+thisid+'/'+1+'/'+thisvalue,
                        success:function(result)
                        {
                            if (result==1){
                                alert("成功")
                            }
                        }
                    });
                }else {
                    //资源组
                    $.ajax({
                        type: 'POST',
                        url: '/group/updateFileGroup/'+thisid+'/'+1+'/'+thisvalue,
                        success:function(result)
                        {
                            if (result==1){
                                alert("成功")
                            }
                        }
                    });
                }

                $(this).parent().removeClass('input').html($(this).val() || 0);
            });
        }).hover(function(){
            $(this).addClass('hover');
        },function(){
            $(this).removeClass('hover');
        });

    })
</script>

</html>